
{include file="public/meta" /}
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>URL规则</h5>
                        <div class="ibox-tools">
                            <a class="link">
                                <b>
                                    <i class="layui-icon layui-icon-refresh"></i>
                                </b>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="layui-card">
                            <div class="layui-card-header layui-bg-orange">警告！非管理员请勿操作！</div>
                        </div>
                        <div class="row">
                            <!--搜索框开始-->
                            <div class="col-sm-12">
                                <div class="layui-form layui-form-item">
                                    <!--搜索框开始-->
                                    <div class="col-sm-12">
                                        <div class="layui-form layui-form-item">
                                            <div class="layui-input-inline layui-form">
                                                <input type="text" id="keyword" class="layui-input" name="keyword" value="" placeholder="关键字" maxlength="10" autocomplete="off" />
                                            </div>
                                            <div class="layui-input-inline">
                                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                                <button  class="layui-btn layui-btn-normal message">添加</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <table id="demo" class="layui-hide" lay-filter="test"></table>
                        <script type="text/html" id="opeBar">
                            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                        </script>
                        <script type="text/html" id="title">
                            {{#  if(d.level === 1){ }}
                                |--{{d.title}}
                            {{#  } }}
                            {{#  if(d.level === 2){ }}
                                |&emsp;|----{{d.title}}
                            {{#  } }}
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use('table', function(){
            var table = layui.table
                , form = layui.form;
            //第一个实例
            table.render({
                elem: '#demo'
                //,height: 312
                ,url: "{:url('admin/menu/rule_index')}" //数据接口
                ,page: true //开启分页
                ,response: {
                    statusCode: 200 //成功的状态码，默认：0
                }
                , size: 'lg' //sm小尺寸的表格 lg大尺寸
                , cellMinWidth: 150
                , limits: [5, 10, 15, 20, 25, 30]
                , limit: "{:config('pages')}"
                , toolbar: '#toolbarDemo'
                , defaultToolbar: ['filter','exports'] //工具类
                , loading: true
                , id: 'test'
                ,cols: [[ //表头
                    {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                    ,{field: 'title', title: '权限名',templet:'#title'}
                    ,{field: 'name', title: 'URL'}
                    ,{field: 'level', title: '级别',width:100}
                    ,{field: 'tip', title: '备注'}
                    ,{fixed: 'right', width:150, title: '操作', align: 'center', toolbar: '#opeBar'}
                ]]
            });
            //监听搜索
            form.on('submit(LAY-search)', function (data) {
                //执行重载
                table.reload('test', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: data.field
                });
            });
            //监听工具条
            table.on('tool(test)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    layer.confirm('真的删除么', function(index){
                        var load = layer.load();
                        $.ajax({
                            url:"{:url('admin/menu/rule_index_del')}",
                            type:'get',
                            dataType:'json',
                            data:{id:data.id},
                            success:function(res){
                                if (res.data == 1) {
                                    layer.close(load);
                                    layer.msg(res.message);
                                    setTimeout('window.location.reload()',1000);
                                } else if (res.data == 0) {
                                    layer.open({
                                        title: '删除失败'
                                        ,content: res.message
                                    });
                                } else {
                                    layer.open({
                                        title: '删除失败'
                                        ,content: '出现未知错误，如果问题一直出现，您可以联系管理员或站点留言'
                                    });
                                }
                            }
                        })
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        shade: false,
                        area: ['650px','650px'],
                        maxmin: true,
                        content: "{$domain}/auth_rule_edit.html?id="+obj.data.id,
                        zIndex: layer.zIndex, //重点1
                        success: function(layero){
                            layer.setTop(layero); //重点2
                        }
                    });
                }
            });
        });
    </script>
    <script>
        layui.use('layer', function() {
            var $ = layui.jquery, layer = layui.layer;
            //触发事件
            $('.message').on('click', function () {
                layer.open({
                    type: 2,
                    shade: false,
                    area: ['600px','650px'],
                    maxmin: true,
                    title:"URL规则_添加",
                    content: "{:url('admin/menu/rule_index_add')}",
                    zIndex: layer.zIndex, //重点1
                    success: function(layero){
                        layer.setTop(layero); //重点2
                    }
                });
            });
        });
    </script>
    <!-- 全局js -->
    {include file="public/footer" /}
</body>
</html>
